# -*- coding: utf-8 -*-
# @Time : 2021/9/17 15:41
# @Author : WANGCHENYI
# @Email : wcy@gmail.com
# @File : MRYX-ST-KBTJ-03.py
# @Project : mryx_test
"""添加商品到购物车后删除"""
from appium import webdriver
from time import sleep
from selenium.webdriver.support.ui import WebDriverWait

desired_capabilities={
    "platformName":"Android",
    "deviceName":"127.0.0.1:62001",
    "platformVersion":"7.1.2",
    "appPackage":" cn.missfresh.application",
    "appActivity":"cn.missfresh.module.main.view.MainActivity",
    "noReset":True
}
driver=webdriver.Remote("http://localhost:4723/wd/hub",desired_capabilities)
#点击口碑推荐榜
driver.find_element_by_id("cn.missfresh.application:id/top_image").click()
#点击商品
sleep(2)
driver.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout[2]/android.widget.FrameLayout/'
                             'android.widget.LinearLayout/android.widget.FrameLayout/android.webkit.WebView/android.webkit.WebView/android.view.View/android.view.View[2]/android.view.View[1]/android.view.View[2]/android.view.View[1]').click()
sleep(2)
#点击加入购物车
driver.find_element_by_xpath('//android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.view.View[1]/android.view.View[1]/android.view.View[1]/android.view.View[1]/android.view.View[3]').click()
sleep(2)
#点击购物车
driver.find_element_by_xpath('//android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.view.View[1]/'
                             'android.view.View[1]/android.view.View[1]/android.view.View[1]/android.widget.ImageView[3]').click()
sleep(4)
#点击删除
driver.find_element_by_xpath('//android.view.View[@content-desc="删除"]').click()
sleep(4)
#确认删除
driver.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.TextView[2]').click()
sleep(3)
driver.quit()